package com.kaiwukj.android.ufamily.mvp.ui.page.dynamic.report;

import androidx.annotation.NonNull;

import com.kaiwukj.android.mcas.mvp.BasePresenter;
import com.kaiwukj.android.mcas.utils.RxLifecycleUtils;
import com.kaiwukj.android.ufamily.mvp.http.callback.ApiCallBack;
import com.kaiwukj.android.ufamily.mvp.http.entity.result.DynamicReportTypeResult;
import com.kaiwukj.android.ufamily.mvp.http.utils.RxUtils;
import com.kaiwukj.android.ufamily.mvp.ui.page.dynamic.DynamicContract;

import java.util.List;

import javax.inject.Inject;

import me.jessyan.rxerrorhandler.core.RxErrorHandler;

public class DynamicReportPresenter extends BasePresenter<DynamicContract.Model, DynamicContract.ReportView> {

    public static final int REPORT = 1;

    @Inject
    RxErrorHandler mErrorHandler;

    @Inject
    public DynamicReportPresenter(DynamicContract.Model model, DynamicContract.ReportView view) {
        super(model, view);
    }

    public void fetchReportType() {
        mModel.fetchReportType()

                .compose(RxUtils.schedulerHelper())
                .compose(RxLifecycleUtils.bindToLifecycle(mRootView))
                .subscribe(new ApiCallBack<List<DynamicReportTypeResult>>(mErrorHandler, mRootView) {
                    @Override
                    public void onSuccess(@NonNull List<DynamicReportTypeResult> result) {
                        mRootView.onFetchReportView(result);
                    }
                });
    }

    public void report(int dynamicId, int typeId) {
        mModel.report(dynamicId, typeId)
                .doOnSubscribe(act -> mRootView.showLoading("正在提交..."))
                .doFinally(() -> mRootView.hideLoading())
                .compose(RxUtils.schedulerHelper())
                .compose(RxLifecycleUtils.bindToLifecycle(mRootView))
                .subscribe(new ApiCallBack<Integer>(mErrorHandler, mRootView, REPORT) {
                    @Override
                    public void onSuccess(@NonNull Integer result) {

                    }
                });
    }

}
